//
//  MainTabbarManager.m
//  iOSProjectExtension
//
//  Created by Apple on 2020/3/1.
//  Copyright © 2020 lidianchao. All rights reserved.
//

#import "MainTabbarManager.h"
#import "CCNavigationController.h"

@implementation NavigationItem
@end

static MainTabbarManager *instance = nil;
@implementation MainTabbarManager
+ (MainTabbarManager *)sharedManager {
    static dispatch_once_t pred;
    dispatch_once(&pred, ^{
        instance = [[MainTabbarManager alloc] init];
    });
    return instance;
}
- (void)getAllNavigationControllers:(void (^)(NSArray * _Nonnull, NSArray * _Nonnull))callback

{
    NavigationItem *mainItem = [[NavigationItem alloc] init];
    MainViewController *mainVc = [[MainViewController alloc] init];
    mainItem.viewController = mainVc;
    mainItem.title = @"首页";
    mainItem.normalImage = @"home_copy";
    mainItem.selectImage = @"home2_copy";
    UINavigationController *mainNaVc = [self createNavWithVc:mainItem];
    
    NavigationItem *categoryItem = [[NavigationItem alloc] init];
    CategoryViewController *category = [[CategoryViewController alloc] init];
    categoryItem.viewController = category;
    categoryItem.title = @"分类";
    categoryItem.normalImage = @"category_copy";
    categoryItem.selectImage = @"category2_copy";
    UINavigationController *categoryNaVc = [self createNavWithVc:categoryItem];

    NavigationItem *cartItem = [[NavigationItem alloc] init];
    CartViewController *cart = [[CartViewController alloc] init];
    cartItem.viewController = cart;
    cartItem.title = @"购物车";
    cartItem.normalImage = @"cart_copy";
    cartItem.selectImage = @"cart2_copy";
    UINavigationController *cartNaVc = [self createNavWithVc:cartItem];

    NavigationItem *myItem = [[NavigationItem alloc] init];
    MineViewController *myView = [[MineViewController alloc] init];
    myItem.viewController = myView;
    myItem.title = @"我的";
    myItem.normalImage = @"my_copy";
    myItem.selectImage = @"my2_copy";
    UINavigationController *myNaVc = [self createNavWithVc:myItem];
    
    
    NSArray *controllers = @[mainNaVc,categoryNaVc,cartNaVc,myNaVc];
    callback(controllers, @[mainVc, category, cart, myView]);
}
///创建Navigation
-(UINavigationController *)createNavWithVc:(NavigationItem *)item
{
    // 设置显示tabbar
    item.viewController.hidesBottomBarWhenPushed = NO;
    item.viewController.title = item.title;
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:item.viewController];
    [navigationController.tabBarItem setImage:[[UIImage imageNamed:item.normalImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [navigationController.tabBarItem setSelectedImage:[[UIImage imageNamed:item.selectImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    return navigationController;
}
@end
